package com.rd.student.jike.class2.xuezhixin.day0728;

import java.io.*;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;

public class Work05 {
    public static void main(String[] args) throws Exception{
        File file = new File("all.txt");
        InputStream is = new FileInputStream(file);
        byte[] arr = new byte[1024];
        is.read(arr);
        String str = new String(arr);
        String str1 = "";
        LinkedList list = new LinkedList();
        for (int i = 0;i<str.length();i++){
            if(str.charAt(i) == '、') {
                list.add(str1);
                str1 = "";
                continue;
            }
            str1 = str1 + "" + str.charAt(i);
        }

        Collections.shuffle(list);
        OutputStream os = new FileOutputStream("random.txt");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入您想随机名字的个数：");
        int num = scanner.nextInt();
        String str2 = "";
        System.out.println("第一波随机到的：");
        for(int i = 0;i<num;i++){
            System.out.println(list.get(i));
            str2 = list.get(i) + "," + str2 ;
        }
        byte[] arr2 = str2.getBytes();
        os.write(arr2);



        LinkedList listLeave = new LinkedList();
        OutputStream os1 = new FileOutputStream("leave.txt");
        System.out.println("您想随机生病的人数：");
        int num2 = scanner.nextInt();
        for (int i = num;i<list.size();i++){
            listLeave.add(list.get(i));
        }
        Collections.shuffle(listLeave);
        String str3 = "";
        System.out.println("生病的人的名字：");
        for (int i = 0;i<num2;i++){
            System.out.println(listLeave.get(i));
            str3 = listLeave.get(i) + "," + str3;
        }
        byte[] arr3 = str3.getBytes();
        os1.write(arr3);



        // 没随机到的且没有生病的
        LinkedList list2 = new LinkedList();
        OutputStream os2 = new FileOutputStream("random.txt");
        for (int i = num2;i<listLeave.size();i++){
            list2.add(listLeave.get(i));
        }
        Collections.shuffle(list2);
        String str4 = str2;
        System.out.println("第三波随机的名字：");
        for (int i = 0;i<num;i++){
            System.out.println(list2.get(i));
            str4 = str4 + "," + list2.get(i);
        }
        byte[] arr4 = str4.getBytes();
        os2.write(arr4);

        os2.close();
        os1.close();
        os.close();
        is.close();
    }
}

